import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

import request from '@/utils/request'

const store = new Vuex.Store({
  state: {
    token: null,
    obs: {
      signature: '',
      policy: '',
      Accesskeyid: '',
      action: ''
    },
  },
  getters: {
    obs: state => {
      return state.obs;
    },
    token: state => {
      return state.token;
    },
  },
  mutations: {
    SET_OBS: (state, obs) => {
      state.obs = obs
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
  },

  actions: {
    getInfo({ commit, state }) {
      return request({
        url: `/obs?access_token=${state.token}`,
        method: 'get'
      }).then((obs) => {
        commit('SET_OBS', obs)
        return obs
      })
    },
    setToken({ commit }, token) {
      commit('SET_TOKEN', token)
    }
  }

})
export default store
